package leetcode31_40;

/**
 * @author shhjiang_001
 * @create 2020-06-16 17:51
 */
public class Solution38 {
    public String countAndSay(int n) {
        if (n==1){
            return "1";
        } else {
            String s = countAndSay(n - 1);
            s = s+'.';
//            String s1 = null;
            StringBuilder s1 = new StringBuilder();
            int le=0,ri=0;
            while (ri < s.length()){
                if (s.charAt(ri)==s.charAt(le)){
                    ri++;
                }else {
                    s1 = s1.append(ri-le).append(s.charAt(le));
                    le = ri;
                }
            }
            return s1.toString();
        }
    }
    String method(int n ){
        if (n==1){
            return "1";
        } else {
            String s = method(n - 1);
            s = s+'.';
            String s1 = null;
            int le=0,ri=0;
            while (ri < s.length()){
                if (s.charAt(ri)==s.charAt(le)){
                    ri++;
                }else {
                    s1 = s1+(ri-le)+s.charAt(le);
                    le = ri;
                }
            }
            return s1;
        }

    }
}
